<?php
/**
 * 审核日志模型
 * @author Administrator
 *  type ： （1：百县普通预算审核，2：百县补报预算审核，3：百县普通审核，4：百县补报结算审核)
 */
class sAuditLog extends MY_Model{
    function sAuditLog(){
        parent::MY_Model();
        $this->table = 'SAuditLog';
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        //角色列表
        $roleList = $this->config->item('roleList');
        //审核结果
        $auditRs = $this->config->item('auditRs');
        foreach ($list as $k => $v){
            //角色
            $list[$k]['userRoleStr'] = isset($roleList[$v['userRole']]) ? $roleList[$v['userRole']] : '';
            //审核结果
            $list[$k]['auditRs'] = isset($auditRs[$v['auditRs']]) ? $auditRs[$v['auditRs']] : '';   
        }
        return $list;
    }
    /**
     * 添加审核日志
     * @param int $type
     * @param array $data
     * @return bool
     */
    function addLog($type,$data = array()){
        $data['type'] = $type;
        $data['targetId'] || showError('请输入目标审核ID');
        $data['userRole'] || showError('请选择用户角色');
        $data['userId'] || showError('请输入审核用户ID');
        $data['auditRs'] || showError('请输入审核结果');
        isset($data['auditDes']) || showError('请设置审核备注');
        $data['createTime'] = time();
        return $this->add($data);
    }
    /**
     * 获取审核日志列表
     * @param int $type
     * @param int $targetId
     * @return Ambigous <array, string, unknown>
     */
    function getLog($type, $targetId){
        $findList = $this->getNewList(array('targetId'=>$targetId, 'type'=>$type), null, null, '', 'id desc');
        return $findList;
    }
}